package cn.edu.szpt.qqdemov3.d517;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageRequest;
import com.android.volley.toolbox.Volley;

import java.util.ArrayList;
import java.util.List;

import cn.edu.szpt.qqdemov3.R;


public class QQTeamAdapter extends RecyclerView.Adapter<QQTeamAdapter.ViewHolder> {
    private Context context;
    private ArrayList<TeamBean> data;

    private RequestQueue volley;


    public QQTeamAdapter(Context context, ArrayList<TeamBean> data ) {
        this.context = context;
        this.data = data;
        this.volley = Volley.newRequestQueue(context);
    }

    public void setData(ArrayList<TeamBean> data) {
        this.data = data;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ViewHolder viewHolder =null;
        View view = LayoutInflater.from(context).inflate(R.layout.item_team,parent,false);
        viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        TeamBean bean = data.get(position);
        holder.txt1.setText(bean.getCountry());
        holder.txt2.setText(bean.getGroupnum());
        Context context = holder.itemView.getContext();

        String imgUrl = null;
        holder.img1.setImageBitmap(getBitMap(imgUrl));
//        context.getFilesDir()
//        context.getExternalFilesDir()
//        holder.img1.setImageBitmap();
//        holder.img1.setImageBitmap();


    }

    private Bitmap getBitMap(String imgUrl) {

        ImageLoader imageLoader = new ImageLoader(volley, new ImageLoader.ImageCache() {
            @Nullable
            @Override
            public Bitmap getBitmap(String url) {
                return null;
            }

            @Override
            public void putBitmap(String url, Bitmap bitmap) {

            }
        });

        imageLoader.get(VolleyTestActivity.SERVER+imgUrl, new ImageLoader.ImageListener() {
            @Override
            public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {

            }

            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });



        return null;
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView txt1;
        TextView txt2;
        ImageView img1;
        ImageView img2;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
             txt1 = itemView.findViewById(R.id.txt1);
             txt2 =itemView.findViewById(R.id.txt2);
             img1= itemView.findViewById(R.id.img1);
             img2= itemView.findViewById(R.id.img2);
        }
    }
}
